/**
 * @file lavas config
 * @author ashen9(ashen9@qq.com)
 */

'use strict';

const path = require('path');
const BUILD_PATH = path.resolve(__dirname, 'dist');
const isDev = process.env.NODE_ENV === 'development';
const isProd = process.env.NODE_ENV === 'production';

module.exports = {
    build: {
        ssr: false,
        path: BUILD_PATH,
        publicPath: '/',
        ssrCopy: isDev ? [] : [
            {
                src: 'server.prod.js'
            },
            {
                src: 'node_modules'
            },
            {
                src: 'package.json'
            }
        ]
    },
    router: {
        mode: 'history',
        base: '/',
        pageTransition: {
            type: 'fade',
            transitionClass: 'fade'
        },
        linkActiveClass: 'active',
        rewrite: [
            {
                from: '/login/login',
                to: '/login'
            },
            {
                from: '/login/forget-pwd',
                to: '/forgetPwd'
            },
            {
                from: '/login/reset-pwd',
                to: 'resetPwd'
            },
            {
                from: '/login/select-company',
                to: 'selectCompany'
            },
            {
                from: '/home/main',
                to: '/home'
            },
            {
                from: 'carousel',
                to: 'card'
            },
            {
                from: 'home',
                to: 'reports'
            },
            {
                from: 'reports',
                to: 'none'
            },
            {
                from: '/inform/info',
                to: '/inform'
            },
            {
                from: '/inform/risk',
                to: '/risk/:type/:title'
            },
            {
                from: '/inform/sys-info',
                to: '/sysInfo/:id'
            },
            {
                from: '/inform/info-setting',
                to: '/infoSetting'
            },
            {
                from: '/inform/info-setting',
                to: '/infoSetting'
            },
            {
                from: '/personal/account',
                to: '/account'
            },
            {
                from: '/personal/analysis',
                to: '/analysis'
            },
            {
                from: '/personal/password',
                to: '/password'
            },
            {
                from: '/personal/personal',
                to: '/personal'
            },
            {
                from: '/personal/setting',
                to: '/setting'
            },
            {
                from: '/personal/username',
                to: '/username'
            }
        ],
        routes: [
            {
                pattern: /\/home/,
                lazyLoading: true,
                meta: {
                    keepAlive: true,
                    requiresAuth: true
                }
            },
            {
                pattern: /\/inform/,
                lazyLoading: true,
                meta: {
                    keepAlive: true,
                    requiresAuth: true
                }
            },
            {
                pattern: /\/personal/,
                lazyLoading: true,
                meta: {
                    keepAlive: true,
                    requiresAuth: true
                }
            }
        ]
    },
    serviceWorker: {
        swSrc: path.join(__dirname, 'core/service-worker.js'),
        swDest: path.join(BUILD_PATH, 'service-worker.js'),
        // swPath: '/custom_path/', // specify custom serveice worker file's path, default is publicPath
        globDirectory: BUILD_PATH,
        globPatterns: [
            '**/*.{html,js,css,eot,svg,ttf,woff}'
        ],
        globIgnores: [
            'sw-register.js',
            '**/*.map'
        ],
        appshellUrl: '/appshell',
        dontCacheBustUrlsMatching: /\.\w{8}\./
    }
};
